package com.ah.util;  
import java.io.IOException;  
import javax.servlet.Filter;  
import javax.servlet.FilterChain;  
import javax.servlet.FilterConfig;  
import javax.servlet.ServletException;  
import javax.servlet.ServletRequest;  
import javax.servlet.ServletResponse;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
import javax.servlet.http.HttpSession;  
public class MyFilter implements Filter {  
    @Override  
    public void destroy() {  
        // TODO Auto-generated method stub  
    }  
    @Override  
    public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain filterchain)  
            throws IOException, ServletException {  
        HttpServletRequest request = (HttpServletRequest) srequest;  
        HttpServletResponse response = (HttpServletResponse) sresponse;  
        // 错误信息  
        HttpSession s = request.getSession();  
        s.setAttribute("msg", "U have a Err");  
        // 页面跳转  
        request.getRequestDispatcher("../filterTarget.jsp").forward(request, response);  
        // 下一个验证  
        filterchain.doFilter(request, response);  
    }  
    @Override  
    public void init(FilterConfig arg0) throws ServletException {  
        // TODO Auto-generated method stub  
    }  
}
